package Beans;

import Entities.TblAcademic;
import Entities.TblClass;
import Entities.TblStudent;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@SessionScoped
public class AcademicManagedBean extends TblAcademic implements Serializable {

    /** Creates a new instance of AcademicManagedBean */
    public AcademicManagedBean() {
        super();
    }
    private List<TblAcademic> all;
    private static TblAcademic academicBean;    

    public List<TblAcademic> getAll() {
        try {
            return new BLL.AcademicBLL().getAll();
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public String add() {
        try {
            new BLL.AcademicBLL().add(this.academicBean);
            return "branchlist";
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return "null";
        }
    }

    public String update() throws Exception {
        if (new BLL.AcademicBLL().update(this.academicBean)) {
            return "academiclist";
        } else {
            return "null";
        }
    }

    public String delete() throws Exception {
        if (new BLL.AcademicBLL().delete(this.academicBean)) {
            return "academiclist";
        } else {
            return "null";
        }
    }

    public String ClassNameById(int classId) {
        TblClass objClass = new BLL.ClassBLL().getById(classId);
        return objClass.getClassName();
    }

    public TblAcademic getAcademicBean() {
        return academicBean;
    }

    public void setAcademicBean(TblAcademic academicBean) {
        this.academicBean = academicBean;
    }

    public String studentDetail() {
        TblStudent std = new BLL.StudentBLL().getById(AcademicManagedBean.academicBean.getStudentRollNo());
        new StudentManagedBean().setStudentSelected(std);
        return "studentdetail";
    }
}
